// pages/set_news/set_news.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hid:"",
    gh_tp:"",
    wz_tip:"",
    order_tip:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getHospital();
    var that = this;
    app.util.request({
      'url':"entry/wxapp/index.techen",
      success:function(res){
        var msg = res.data.wxapp_mb
        that.setData({
          gh_tip:msg.overtime,
          wz_tip:msg.Mobile,
          order_tip:msg.orderSuccess
        })
      }
    })
  },
  getHospital:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/regin.hospitals",
      data:{
        openid:wx.getStorageSync("openid"),
      },
      success:function(res){
        that.setData({
          info:res.data,
          hid:res.data.hid
        })
      }
    })
  },
  addNum:function(){
    var that = this;
    var gh_tip = that.data.gh_tip;
    var hid = that.data.hid;
    if(gh_tip != '')
    {
      wx.requestSubscribeMessage({
        tmplIds: [gh_tip],
        success: (res) => {
          console.log(res)
          //调用授权
          let item = res[gh_tip]
          if (item == "accept") {
            app.util.request({
              'url': 'entry/wxapp/regin.addnumber',
              data: {
                hid: hid,
                key: 'gh_number'
              },
              success: function (res) {
                console.log(res)
                that.getHospital()
              }
            })
          }
  
        }
      })
    }else{
      wx.showModal({
        title: '提示',
        content:"请先在后台添加挂号订阅消息"
      })
    }
    
  },
  addNumwz:function(){
    var that = this;
    var wz_tip = that.data.wz_tip;
    var hid = that.data.hid;
    if(wz_tip != '')
    {
      wx.requestSubscribeMessage({
        tmplIds: [wz_tip],
        success: (res) => {
          console.log(res)
          //调用授权
          let item = res[gh_tip]
          if (item == "accept") {
            app.util.request({
              'url': 'entry/wxapp/regin.addnumber',
              data: {
                hid: hid,
                key: 'wz_number'
              },
              success: function (res) {
                console.log(res)
                that.getHospital()
              }
            })
          }
  
        }
      })
    }else{
      wx.showModal({
        title: '提示',
        content:"请先在后台添加问诊订阅消息"
      })
    }
    
  },
  addNum2:function(){
    var that = this;
    var order_tip = that.data.order_tip;
    var hid = that.data.hid;
    if(order_tip != '')
    {
      wx.requestSubscribeMessage({
        tmplIds: [order_tip],
        success: (res) => {
          console.log(res)
          //调用授权
          let item = res[order_tip]
          if (item == "accept") {
            app.util.request({
              'url': 'entry/wxapp/regin.addnumber',
              data: {
                hid: hid,
                key: 'order_number'
              },
              success: function (res) {
                console.log(res)
                that.getHospital()
              }
            })
          }
  
        }
      })
    }else{
      wx.showModal({
        title: '提示',
        content:"请先在后台添加订单订阅消息"
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})